﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Marbles.Data
{
    public class DataSourceColumn
    {

        public SqlDbType DataType { get { return this._datatype; } }
        public Type NativeType { get { return BaseDataSource.GetNativeType(this._datatype); } }
        public string Name { get { return this._name; } }
        public string Description { get { return this._description; } }
        public string DefaultValue { get { return this._defaultvalue; } }
        public int Width { get { return this._width; } }
        public int NumericPrecision { get { return this._precision; } }
        public int NumericScale { get { return this._scale; } }
        public bool PrimaryKey { get { return this._primarykey; } }
        public bool Unique { get { return this._unique; } }
        public bool Nullable { get { return this._nullable; } }

        private SqlDbType _datatype;
        private string _name = string.Empty;
        private int _width = 0;
        private int _precision = 0;
        private int _scale = 0;
        private bool _primarykey = false;
        private bool _unique = false;
        private bool _nullable = false;
        private string _description = string.Empty;
        private string _defaultvalue = string.Empty;

        public DataSourceColumn(string Name, SqlDbType DataType, bool PrimaryKey, bool Unique, bool Nullable, string Description, string DefaultValue)
        {
            this._description = Description;
            this._width = 0;
            this._precision = 0;
            this._scale = 0;
            this._name = Name;
            this._datatype = DataType;
            this._primarykey = PrimaryKey;
            this._unique = Unique;
            if (this._primarykey) { this._unique = true; }
            this._nullable = Nullable;
            this._defaultvalue = DefaultValue;
        }

        public DataSourceColumn(string Name, SqlDbType DataType, bool PrimaryKey, bool Unique, bool Nullable, int Width, int Precision, int Scale, string Description, string DefaultValue)
        {
            this._description = Description;
            this._width = Width;
            this._precision = Precision;
            this._scale = Scale;
            this._name = Name;
            this._datatype = DataType;
            this._primarykey = PrimaryKey;
            this._unique = Unique;
            if (this._primarykey) { this._unique = true; }
            this._nullable = Nullable;
            this._defaultvalue = DefaultValue;
        }

        public DataSourceColumn(string Name, SqlDbType DataType, bool PrimaryKey, bool Unique, bool Nullable, int Width, string Description, string DefaultValue)
        {
            this._defaultvalue = DefaultValue;
            this._description = Description;
            this._width = Width;
            this._precision = 0;
            this._scale = 0;
            this._name = Name;
            this._datatype = DataType;
            this._primarykey = PrimaryKey;
            this._unique = Unique;
            if (this._primarykey) { this._unique = true; }
            this._nullable = Nullable;
        }

        public override string ToString()
        {
            return this._name;
        }
    }
}
